package top.wugy.blog.web;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.redis.Redis;
import top.wugy.blog.kits.Const;

/**
 * 全局请求拦截，判断是否已登录
 * <p>
 * wugy on 2017/11/9 14:27
 */
public class GlobalInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        String loginTime = Redis.use(Const.REDIS_CACHE).get(Const.LOGIN_TIME);
        controller.setAttr("isLogin", StrKit.notBlank(loginTime));
        inv.invoke();
    }
}
